package com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.User;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.dao.DoctorLookedDao;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.dao.DentalImageDao;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.QualityAssuranceInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.RootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.SearchQualityAssuranceInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.SearchRootImageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.service.IDentalImageService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 质量管理Dao
 *
 * @author fengshuonan
 * @Date 2019-09-01 15:34:05
 */
@Service
public class DentalImageServiceImpl implements IDentalImageService {
    @Autowired
    private DentalImageDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<QualityAssuranceInfo> selectPageListByQuality(Page<QualityAssuranceInfo> page, SearchQualityAssuranceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartUploadTime())) {
            params.put("startUploadTime", searchInfo.getStartUploadTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUploadTime())) {
            params.put("endUploadTime", searchInfo.getEndUploadTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAddName())) {
            params.put("addName", searchInfo.getAddName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getScoreTOTAL())) {
            if("1".equals(searchInfo.getScoreTOTAL())){
                params.put("scoreTOTAL", "" +
                        "(select sum( " +
                        "        g.A1 / 3 + g.A2 / 3 + g.A3 / 3 + " +
                        "        IF (g.photo_type IN(1, 3), 0, g.A4) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A5) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A6) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A7) " +
                        "        ) from (SELECT " +
                        "        d.photo_type as photo_type,d.A1,d.A2,d.A3,d.A4,d.A5,d.A6,d.A7,e.num " +
                        "        FROM " +
                        "        icon_infos e " +
                        "        LEFT JOIN intelligent_score_details_info2 d ON e.id = d.id2 GROUP BY e.id) g where g.num = t1.num) " +
                        ">=(SELECT score from inco_info_standard limit 1 )");
            } else {
                params.put("scoreTOTAL", "" +
                        "(select sum( " +
                        "        g.A1 / 3 + g.A2 / 3 + g.A3 / 3 + " +
                        "        IF (g.photo_type IN(1, 3), 0, g.A4) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A5) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A6) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A7) " +
                        "        ) from (SELECT " +
                        "        d.photo_type as photo_type,d.A1,d.A2,d.A3,d.A4,d.A5,d.A6,d.A7,e.num " +
                        "        FROM " +
                        "        icon_infos e " +
                        "        LEFT JOIN intelligent_score_details_info2 d ON e.id = d.id2  " +
                        "        GROUP BY e.id) g where g.num = t1.num)" +
                        "<(SELECT score from inco_info_standard limit 1 )");
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPages(page, params);
    }

    @Override
    public int getQueryPageCount(Page<QualityAssuranceInfo> page, SearchQualityAssuranceInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getStartUploadTime())) {
            params.put("startUploadTime", searchInfo.getStartUploadTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUploadTime())) {
            params.put("endUploadTime", searchInfo.getEndUploadTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAddName())) {
            params.put("addName", searchInfo.getAddName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getScoreTOTAL())) {
            if("1".equals(searchInfo.getScoreTOTAL())){
                params.put("scoreTOTAL", "" +
                        "(select sum( " +
                        "        g.A1 / 3 + g.A2 / 3 + g.A3 / 3 + " +
                        "        IF (g.photo_type IN(1, 3), 0, g.A4) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A5) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A6) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A7) " +
                        "        ) from (SELECT " +
                        "        d.photo_type as photo_type,d.A1,d.A2,d.A3,d.A4,d.A5,d.A6,d.A7,e.num " +
                        "        FROM " +
                        "        icon_infos e " +
                        "        LEFT JOIN intelligent_score_details_info2 d ON e.id = d.id2 GROUP BY e.id) g where g.num = t1.num) " +
                        ">=(SELECT score from inco_info_standard limit 1 )");
            } else {
                params.put("scoreTOTAL", "" +
                        "(select sum( " +
                        "        g.A1 / 3 + g.A2 / 3 + g.A3 / 3 + " +
                        "        IF (g.photo_type IN(1, 3), 0, g.A4) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A5) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A6) + " +
                        "        IF (g.photo_type IN(1, 2), 0, g.A7) " +
                        "        ) from (SELECT " +
                        "        d.photo_type as photo_type,d.A1,d.A2,d.A3,d.A4,d.A5,d.A6,d.A7,e.num " +
                        "        FROM " +
                        "        icon_infos e " +
                        "        LEFT JOIN intelligent_score_details_info2 d ON e.id = d.id2  " +
                        "        GROUP BY e.id) g where g.num = t1.num)" +
                        "<(SELECT score from inco_info_standard limit 1 )");
            }
        }
        return dao.getQueryPageCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByOrthodontics(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            params.put("type", searchInfo.getType());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        if(StringUtil.isNotEmpty(searchInfo.getCorea())){
            if("1".equals(searchInfo.getCorea())){
                params.put("corea", "( "+ " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " +" SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesOrthodontics(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByOrthodontics1(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getHeeStatus())) {
            params.put("heeStatus", searchInfo.getHeeStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            if("初诊".equals(searchInfo.getType())){
                params.put("type","t1.status = 1");
            }
           else if("下半口".equals(searchInfo.getType())){
                params.put("type","t1.status = 1 and t1.shu_status=1");
            }
            else if("完成".equals(searchInfo.getType())){
                params.put("type","t1.status = 3 ");
            }
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        if(StringUtil.isNotEmpty(searchInfo.getCorea())){
            if("1".equals(searchInfo.getCorea())){
                params.put("corea", "( "+ " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " +" SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesOrthodontics1(page, params);
    }

    @Override
    public int getOrthodonticsPageCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            params.put("type", searchInfo.getType());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        if (StringUtil.isNotEmpty(searchInfo.getHeeStatus())) {
            params.put("heeStatus", searchInfo.getHeeStatus());
        }
        if(StringUtil.isNotEmpty(searchInfo.getCorea())){
            if("1".equals(searchInfo.getCorea())){
                params.put("corea", "( "+ " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " +" SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        return dao.getQueryPagesOrthodonticsCount(page, params);
    }

    @Override
    public int getOrthodonticsPageCount1(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getHeeStatus())) {
            params.put("heeStatus", searchInfo.getHeeStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getType())) {
            if("初诊".equals(searchInfo.getType())){
                params.put("type","t1.status = 1");
            }
            else if("下半口".equals(searchInfo.getType())){
                params.put("type","t1.status = 1 and t1.shu_status=1");
            }
            else if("完成".equals(searchInfo.getType())){
                params.put("type","t1.status = 3 ");
            }
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        if(StringUtil.isNotEmpty(searchInfo.getCorea())){
            if("1".equals(searchInfo.getCorea())){
                params.put("corea", "( "+ " SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)>=(SELECT score from inco_info_orthodontics limit 1 )");
            } else {
                params.put("corea", "( " +" SELECT sum(g.A1+g.A2+g.A3+g.A4+g.A5+g.A6+g.A7) FROM root_orthodontics_info g where g.num= t1.num)<(SELECT score from inco_info_orthodontics limit 1 )");
            }
        }
        return dao.getQueryPagesOrthodonticsCount1(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByCanal(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesCanal(page, params);
    }

    @Override
    public int getQueryPageCanalCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        return dao.getQueryPagesCanalCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByPeriodontal(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesPeriodontal(page, params);
    }

    @Override
    public int getQueryPagePeriodontalCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        return dao.getQueryPagesPeriodontalCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByPlant(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesPlant(page, params);
    }

    @Override
    public int getQueryPagePlantCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        return dao.getQueryPagesPlantCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByRepair(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesRepair(page, params);
    }

    @Override
    public int getQueryPageRepairCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        return dao.getQueryPagesRepairCount(page, params);
    }

    @Override
    public List<RootImageInfo> selectPageListByScaling(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPagesScaling(page, params);
    }

    @Override
    public int getQueryPageScalingCount(Page<RootImageInfo> page, SearchRootImageInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getStartCreateTime())) {
            params.put("startCreateTime", searchInfo.getStartCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndCreateTime())) {
            params.put("endCreateTime", searchInfo.getEndCreateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getReservationsId())) {
            params.put("reservationsId", searchInfo.getReservationsId());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCreateName())) {
            params.put("createName", searchInfo.getCreateName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore())) {
            params.put("arrivalStore", searchInfo.getArrivalStore());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStatus())) {
            params.put("status", searchInfo.getStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArea())) {
            params.put("area", searchInfo.getArea());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }else {
            String sql = "select b.id as roleid from user a left join role b on a.roleId=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
            User user = sqlMapper.selectOne(sql, User.class);
            if (user != null) {
                if ("1".equals(user.getRoleid()) || "1,".equals(user.getRoleid().substring(0, 2))) {
                    params.put("doctor", "");
                } else {
                    params.put("doctor", ShiroKit.getUser().getAccount());
                }
            }
        }
        return dao.getQueryPagesScalingCount(page, params);
    }
}
